
Ext.define('cloud.controller.User', {
    extend: 'Ext.app.Controller',
    requires: ['Ext.picker.Picker'],
    config: {
        refs: {
            user: 'user',
            userDetail:'userDetail',
            user_edit:'userDetail #user_edit',
            user_delet:'userDetail #user_delet',
            user_status:'userDetail #user_status',
            search_user:'user #search_user'

        },
        control: {
            "user list":{
                itemtap: function (list, item, index, record) {
                    Ext.Viewport.mask({xtype: 'loadmask'});
                    var userDetail = this.getUserDetail()||Ext.create('cloud.view.user.UserDetail',{title:record.get('name')});
                    var form=this.getUser().push(userDetail);
                    form.setRecord(record);
                    Ext.Viewport.unmask();
                }
            },
            search_user: {
                change: function () {
                    var Store = Ext.getStore('UsersAllFindStore');
                    var value = this.getSearch_user().getValue();
                    Store.clearFilter();
                    if (value != "") {
                        Store.filter('name', value, true);
                    }
                    Store.load({params: {caid: localStorage.getItem('caid')}});
                }
            },
            user_edit:{
                tap:function(){
                    Ext.Viewport.mask({xtype: 'loadmask'});
                    this.getUserDetail().submit({
                        url: GLOBAL.api_url + 'users_status_update',
                        scope: this,
                        method: 'POST',
                        success: function (from, result){
                            Ext.Viewport.unmask();
                            if (result.Variables.Result.code == 0) {
                                this.getUser().pop()
                            }
                            Ext.getStore('UsersAllFindStore').load({params: {caid: localStorage.getItem('caid')}});
                            Ext.Msg.alert(result.Variables.Message.messagestr);
                        },
                        failure:function(){
                            Ext.Viewport.unmask();
                            Ext.Msg.alert('请求失败', '服务器维护中....');
                        }
                    })
                }
            }
        }
    }
});